#include <stdio.h>
#include "include/modbus/modbus.h"

int main(void) 
{
    int ret;
    modbus_t *mb;
    uint16_t tab_reg[32] = {0};

    mb = modbus_new_tcp("192.168.31.243", 502);
    modbus_set_slave(mb, 1);
    ret = modbus_connect(mb);
    if(ret < 0)
    {
        printf("connect err\n");
        return -1;
    }
    /* Read 5 registers from the address 0 */
    ret = modbus_read_registers(mb, 0, 5, tab_reg);
    if(ret < 0)
    {
        printf("read err\n");
        return -1;
    }

#if 0    
    for (int i = 0; i < sizeof(tab_reg); i++)
    {
        printf("0x%02x ", tab_reg[i]);
    }
    printf("\n");
#endif

    float val = modbus_get_float_dcba(tab_reg);
    printf("val = %f\n", val);

    modbus_close(mb);
    modbus_free(mb);
}